home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / pmenv.zip / PRINTSUP.C < prev    next >
C/C++ Source or Header  |  1993-03-01  |  3KB  |  124 lines

  1. #include <string.h>
  2.  
  3. #define INCL_DEV
  4. #define INCL_GPILCIDS
  5. #define INCL_WINFRAMEMGR
  6. #define INCL_WINSHELLDATA
  7. #include <os2.h>
  8.  
  9. #include "printsup.h"
  10.  
  11.  
  12. /* ----------------------------------------------------------------- */
  13.  
  14. VOID PrintLinesAt (HPS hps, POINTL ptl,
  15.     PSZ pszBuf, LONG lMaxBaselineExt)
  16. {
  17.     /*
  18.      *  Print the lines of text in a buffer, starting at the indicated
  19.      *  position.  The lines must be separated by either carriage
  20.      *  returns, or carriage return/line feed pairs.
  21.      */
  22.  
  23.     PSZ     pszLine;
  24.  
  25.     pszLine = strtok (pszBuf, "\r");
  26.  
  27.     while (pszLine)
  28.     {
  29.         if (*pszLine == '\n')       /* Skip over line feed if present */
  30.             ++pszLine;
  31.  
  32.         GpiCharStringAt (hps, &ptl,
  33.             (LONG) strlen (pszLine), pszLine);
  34.         ptl.y -= lMaxBaselineExt;
  35.  
  36.         pszLine = strtok (0, "\r");
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. /* ----------------------------------------------------------------- */
  43.  
  44. VOID PrintString (HDC hdcPrint, PSZ psz)
  45. {
  46.     /*
  47.      *  Print a zero-terminated string by sending as raw data.
  48.      */
  49.  
  50.     DevEscape (hdcPrint, DEVESC_RAWDATA, (LONG) strlen (psz),
  51.         psz, 0L, 0);
  52. }
  53.  
  54.  
  55.  
  56. /* ----------------------------------------------------------------- */
  57.  
  58. USHORT OpenDefaultPrinterDC (HAB hab, PHDC phdcPrint,
  59.     PSZ pszDataType)
  60. {
  61.     CHAR            achPrnData[256];
  62.     DRIVDATA        driv;
  63.     CHAR            achDefPrnName[34], *pchDelimiter;
  64.     DEVOPENSTRUC    dop;
  65.  
  66.  
  67.  
  68.     PrfQueryProfileString (HINI_PROFILE,
  69.     "PM_SPOOLER", "PRINTER",
  70.     ";", achDefPrnName, sizeof achDefPrnName);
  71.  
  72.     if ((pchDelimiter = strchr (achDefPrnName, ';')) != NULL)
  73.     *pchDelimiter = '\0';
  74.  
  75.     if (achDefPrnName[0] == '\0')
  76.     return DEV_ERROR;
  77.  
  78.     //Obtain information on default printer
  79.  
  80.     PrfQueryProfileString (HINI_PROFILE,
  81.     "PM_SPOOLER_PRINTER", achDefPrnName,
  82.     ";;;;", achPrnData, (ULONG) sizeof achPrnData);
  83.  
  84.     //Parse printer information string
  85.  
  86.     if ((pchDelimiter = strchr (achPrnData, ';')) == NULL)
  87.     return DEV_ERROR;
  88.  
  89.     dop.pszDriverName = pchDelimiter + 1;
  90.  
  91.     if ((pchDelimiter = strchr (dop.pszDriverName, ';')) == NULL)
  92.     return DEV_ERROR;
  93.  
  94.     dop.pszLogAddress = pchDelimiter + 1;
  95.  
  96.     *(dop.pszLogAddress + strcspn (dop.pszLogAddress, ",;")) = '\0';
  97.     *(dop.pszDriverName + strcspn (dop.pszDriverName, ",;")) = '\0';
  98.  
  99.     //Fill DRIVDATA structure if necessary
  100.  
  101.     if ((pchDelimiter = strchr (dop.pszDriverName, '.')) != NULL)
  102.     {
  103.         *pchDelimiter = '\0';
  104.         memset (&driv, 0, sizeof driv);
  105.         driv.cb = sizeof driv;
  106.         strncpy (driv.szDeviceName, pchDelimiter + 1,
  107.             sizeof (driv.szDeviceName));
  108.         dop.pdriv = &driv;
  109.     }
  110.     else
  111.         dop.pdriv = NULL;
  112.  
  113.     //Set data type
  114.  
  115.     dop.pszDataType = pszDataType;
  116.  
  117.     //Open printer device context
  118.  
  119.     *phdcPrint = DevOpenDC (hab, OD_QUEUED, "*", 4L,
  120.     (PDEVOPENDATA) & dop, 0);
  121.  
  122.     return 1;
  123. }
  124.